COUNT

统计指定列具有非空值的行数。

语法

COUNT ( <ColumnName> )
参数 属性 描述
列名 包含要计数的值的列

返回值

#标量 一个整数

备注

COUNT 只允许使用列作为参数,可以对包含以下类型的值的行进行计数:

COUNT 跳过空白值。 不支持 TRUE/FALSE 值。如果要计算 TRUE/FALSE 值的列,请使用 COUNTA 函数。

COUNT 函数在内部执行 COUNTX,两者没有任何性能差异。

示例

--  COUNT is the short version of COUNTX, when used with one column only
--  In DAX, there are no differences between COUNTA and COUNT
--  COUNTX can be expressed in a more explicit way by using CALCULATE
--  and COUNTROWS
DEFINE
    MEASURE Customer[# Customers]     = COUNTROWS ( Customer )
    MEASURE Customer[# Individuals 1] = COUNT ( Customer[Customer Name] )
    MEASURE Customer[# Individuals 2] = COUNTX ( Customer, Customer[Customer Name] )
    MEASURE Customer[# Individuals 3] =
        CALCULATE (
            COUNTROWS ( Customer ),
            NOT ISBLANK ( Customer[Customer Name] )
        )
EVALUATE
SUMMARIZECOLUMNS (
    Customer[Continent],
    "# Customers",     [# Customers],
    "# Individuals 1", [# Individuals 1],
    "# Individuals 2", [# Individuals 2],
    "# Individuals 3", [# Individuals 3]
)

不计算空值,但是会计算空字符串

--  COUNT does not count blanks, but it counts empty strings
--  using the CALCULATE version, the code is clearer
DEFINE
    MEASURE Customer[# COUNT] = COUNT ( Customer[Customer Name] )
    MEASURE Customer[# NO BLANKS] =
        CALCULATE (
            COUNTROWS ( Customer ),
            NOT ISBLANK ( Customer[Customer Name] )
        )
    MEASURE Customer[# NO BLANKS / EMPTY STRINGS] =
        CALCULATE (
            COUNTROWS ( Customer ),
            Customer[Customer Name] <> ""
        )
EVALUATE
SUMMARIZECOLUMNS (
    Customer[Continent],
    "# COUNT", [# COUNT],
    "# NO BLANKS", [# NO BLANKS],
    "# NO BLANKS / EMPTY STRINGS", [# NO BLANKS / EMPTY STRINGS]
)

相关函数

COUNTA
COUNTX
COUNTAX